// layeredtest1.cpp : Defines the entry point for the application.
//

#include "stdafx.h"
#include <stdio.h>
#include "resource.h"
#include <math.h>
#include <time.h>
#include "hsv.h"
#define MAX_LOADSTRING 100

#define WS_EX_LAYERED           0x00080000
//#define AC_SRC_OVER				0x00000000; 
#define AC_SRC_ALPHA			0x00000001; 
//#define AC_SRC_NO_PREMULT_ALPHA 0x00000001; 
//#define AC_SRC_NO_ALPHA			0x00000002; 
//#define AC_DST_NO_PREMULT_ALPHA 0x00000010; 
//#define AC_DST_NO_ALPHA			0x00000020; 
#define LWA_COLORKEY			0x00000001; 
#define LWA_ALPHA				0x00000002; 
#define ULW_COLORKEY			0x00000001 
#define ULW_ALPHA				0x00000002 
#define ULW_OPAQUE				0x00000004
typedef BOOL (WINAPI *lpfnUpdateLayeredWindow)(HWND hWnd, HDC hdcDst, POINT *pptDst, SIZE *psize, HDC hdcSrc, POINT *pptSrc, COLORREF crKey, BLENDFUNCTION *pblend, DWORD dwFlags);
typedef BOOL (WINAPI *lpfnSetLayeredWindowAttributes)(HWND hWnd, COLORREF crKey, BLENDFUNCTION *pblend, DWORD dwFlags);
typedef BOOL (WINAPI *lpfnAlphaBlend)(HDC hdcDest,int nXOriginDest,int nYOriginDest,int nWidthDest,int nHeightDest,HDC hdcSrc,int nXOriginSrc,int nYOriginSrc,int nWidthSrc,int nHeightSrc,BLENDFUNCTION blendFunction);
lpfnUpdateLayeredWindow UpdateLayeredWindow;
lpfnSetLayeredWindowAttributes SetLayeredWindowAttributes;
lpfnAlphaBlend AlphaBlend2;
HDC hDC;
HWND hWnd;
HDC hScreenDC;
HBITMAP hBitmap;
HBITMAP hOldBitmap;
PBYTE pBits,pTemp;
BYTE *data;
BOOL bDrag=FALSE;
int t=0;
int Lastx,Lasty,xPos,yPos;
POINT ptLast,ptNow;
SIZE size={128,128};
POINT point={0,0};
POINT ptSrc={0,0};
BLENDFUNCTION blend;
hsv hsv;
time_t StartTime;
time_t CurrentTime;
double WorkTimeLimit=1*3600;//in second
double WorkTime=0;
// Global Variables:
HINSTANCE hInst;								// current instance
TCHAR szTitle[MAX_LOADSTRING];								// The title bar text
TCHAR szWindowClass[MAX_LOADSTRING];								// The title bar text

// Foward declarations of functions included in this code module:
ATOM				MyRegisterClass(HINSTANCE hInstance);
BOOL				InitInstance(HINSTANCE, int);
BOOL				InitLayer();
LRESULT CALLBACK	WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK	About(HWND, UINT, WPARAM, LPARAM);
DrawAlarmLight(HDC hDC,float angle,float halfwidth);
DrawRadiationAlarm(HDC hDC,float angle);
int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
 	// TODO: Place code here.
	MSG msg;
	HACCEL hAccelTable;

	// Initialize global strings
	LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
	LoadString(hInstance, IDC_LAYEREDTEST1, szWindowClass, MAX_LOADSTRING);
	MyRegisterClass(hInstance);

	HMODULE hUser32 = GetModuleHandle(_T("USER32.DLL"));
	HMODULE hGdi32 = GetModuleHandle(_T("GDI32.DLL"));
	UpdateLayeredWindow = (lpfnUpdateLayeredWindow)GetProcAddress(hUser32, "UpdateLayeredWindow");
	SetLayeredWindowAttributes = (lpfnSetLayeredWindowAttributes)GetProcAddress(hUser32, "SetLayeredWindowAttributes");
	AlphaBlend2 = (lpfnAlphaBlend)GetProcAddress(hGdi32, "GdiAlphaBlend");
	
	//ASSERT(UpdateLayeredWindow);
	if (NULL == UpdateLayeredWindow)
	{
		MessageBox(NULL,"Not Found Layered Window Support","Error",MB_OK);
		return FALSE;
	}
	if (NULL == SetLayeredWindowAttributes)
	{
		MessageBox(NULL,"Not Found Layered Window Support","Error",MB_OK);
		return FALSE;
	}
	if (NULL == AlphaBlend2)
	{
		MessageBox(NULL,"Not Found Alpha Blend Support","Error",MB_OK);
		return FALSE;
	}
	// Perform application initialization:
	if (!InitInstance (hInstance, nCmdShow)) 
	{
		return FALSE;
	}
	InitLayer();
	int bpp=GetDeviceCaps(hScreenDC,BITSPIXEL);
	if(bpp<32)
	{
		char str[100];
		sprintf(str,"BitsPerPixel:%d\nThis program only works under 32bpp",bpp);
		MessageBox(NULL,str,"Error",MB_OK);
	}
	SetTimer(hWnd,IDT_TIMER0,1000/30,NULL);
	hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_LAYEREDTEST1);
	time(&StartTime);
	// Main message loop:
	while (GetMessage(&msg, NULL, 0, 0)) 
	{
		if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) 
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
	}

	return msg.wParam;
}



//
//  FUNCTION: MyRegisterClass()
//
//  PURPOSE: Registers the window class.
//
//  COMMENTS:
//
//    This function and its usage is only necessary if you want this code
//    to be compatible with Win32 systems prior to the 'RegisterClassEx'
//    function that was added to Windows 95. It is important to call this function
//    so that the application will get 'well formed' small icons associated
//    with it.
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
	WNDCLASSEX wcex;

	wcex.cbSize = sizeof(WNDCLASSEX); 

	wcex.style			= CS_HREDRAW | CS_VREDRAW|CS_OWNDC;
	wcex.lpfnWndProc	= (WNDPROC)WndProc;
	wcex.cbClsExtra		= 0;
	wcex.cbWndExtra		= 0;
	wcex.hInstance		= hInstance;
	wcex.hIcon			= LoadIcon(hInstance, (LPCTSTR)IDI_LAYEREDTEST1);
	wcex.hCursor		= LoadCursor(NULL, IDC_ARROW);
	wcex.hbrBackground	= NULL;
	wcex.lpszMenuName	= NULL;
	//wcex.lpszMenuName	= (LPCSTR)IDC_LAYEREDTEST1;
	wcex.lpszClassName	= szWindowClass;
	wcex.hIconSm		= LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);

	return RegisterClassEx(&wcex);
}

//
//   FUNCTION: InitInstance(HANDLE, int)
//
//   PURPOSE: Saves instance handle and creates main window
//
//   COMMENTS:
//
//        In this function, we save the instance handle in a global variable and
//        create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
	hInst = hInstance; // Store instance handle in our global variable

	hWnd = CreateWindowEx(WS_EX_TOPMOST|WS_EX_LAYERED,szWindowClass, szTitle,WS_POPUP|WS_SYSMENU,
	  0, 0, size.cx,size.cy, NULL, NULL, hInstance, NULL);

	if (!hWnd)
	{
	  return FALSE;
	}
	ShowWindow(hWnd, nCmdShow);
	UpdateWindow(hWnd);
	return TRUE;
}
BOOL InitLayer()
{
	blend.BlendOp = AC_SRC_OVER;
	blend.BlendFlags = 0;
	blend.AlphaFormat = AC_SRC_ALPHA;
	blend.SourceConstantAlpha = 0xff;
	//hdc=GetDC(hWnd);
	hScreenDC=GetDC(NULL);
	hDC=CreateCompatibleDC(NULL);
	//hBitmap=CreateCompatibleBitmap(GetDC(NULL),128,128);
	data=(BYTE*)malloc(size.cx*size.cy*4);
	int i;int j;
	for(i=0;i<size.cy;i++)
	{
		for(j=0;j<size.cx;j++)
		{
			*(data+(i*size.cx+j)*4)=0xff;
			*(data+(i*size.cx+j)*4+1)=0xff0;
			*(data+(i*size.cx+j)*4+2)=0xff0;
			*(data+(i*size.cx+j)*4+3)=0;
		}
	}
	hBitmap=CreateBitmap(size.cx,size.cy,1,32,data);
	//SelectObject(hDC,hBitmap);
	if(hDC==NULL) return FALSE;
		BITMAPINFO *pbmiRGB = (BITMAPINFO *) NULL;
	HBITMAP hbmRGB;
	pbmiRGB = (BITMAPINFO *)LocalAlloc(LMEM_FIXED|LMEM_ZEROINIT, sizeof(BITMAPINFO) );
	if (!pbmiRGB)
	{
		MessageBox(NULL, "Out of memory.", "Error", MB_OK);
	}
	pbmiRGB->bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
	pbmiRGB->bmiHeader.biWidth= 128;
	pbmiRGB->bmiHeader.biHeight= -128;
	pbmiRGB->bmiHeader.biPlanes= 1;
	pbmiRGB->bmiHeader.biBitCount      = 32;
	pbmiRGB->bmiHeader.biCompression   = BI_RGB;
	pbmiRGB->bmiHeader.biSizeImage     = pbmiRGB->bmiHeader.biWidth* abs(pbmiRGB->bmiHeader.biHeight) * 4;
	hbmRGB = CreateDIBSection(hDC, pbmiRGB, DIB_RGB_COLORS,(PVOID *) &pBits, NULL, 0);
	if (!hbmRGB)
	{
		MessageBox(NULL, "Out of memory.", "Error", MB_OK);
	}      
	if (!SelectObject(hDC, hbmRGB))
	{
		MessageBox(NULL, "Out of memory.", "Error", MB_OK);
	} 
	for(i=0;i<size.cy;i++)
	{
		for(j=0;j<size.cx;j++)
		{
			*(pBits+(i*size.cx+j)*4)=0x0;
			*(pBits+(i*size.cx+j)*4+1)=0x0;
			*(pBits+(i*size.cx+j)*4+2)=0x0;
			*(pBits+(i*size.cx+j)*4+3)=0;

			/**(pBits+(i*size.cx+j)*4)=0xff*(j+i)/0xff;
			*(pBits+(i*size.cx+j)*4+1)=0x0;
			*(pBits+(i*size.cx+j)*4+2)=0x0;
			*(pBits+(i*size.cx+j)*4+3)=j+i;*/
		}
	}
	//BitBlt(hDC,0,0,128,128,GetDC(NULL),0,0,SRCCOPY);
	UpdateLayeredWindow(hWnd,hScreenDC,&point,&size,hDC, &ptSrc,RGB(0xff,0xff,0x0),&blend,ULW_ALPHA);
	return TRUE;
}

//
//  FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
//
//  PURPOSE:  Processes messages for the main window.
//
//  WM_COMMAND	- process the application menu
//  WM_PAINT	- Paint the main window
//  WM_DESTROY	- post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	int wmId, wmEvent;
	RECT rect;
	int j,k;
	float r,g,b,i,step=0.25;
	int fwKeys;        // key flags 
	TCHAR ntime[100];
	double el;
	TCHAR szHello[MAX_LOADSTRING];
	LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING);

	switch (message) 
	{
		case WM_TIMER:
			time(&CurrentTime);
			el=difftime(StartTime,CurrentTime);
			pTemp=pBits;
			for(k=0;k<size.cy*size.cx;k++)
			{
				*(pTemp+3)=0;
				*(pTemp)=0;
				*(pTemp+1)=0;
				*(pTemp+2)=0;
				pTemp+=4;
			}
			DrawRadiationAlarm(hDC,t/8.0);
			//DrawAlarmLight(hDC,t/8.0,0.2);
			//BitBlt(hDC,0,0,128,128,hScreenDC,0,0,SRCCOPY);
			/*BitBlt(hDC,0,0,128,128,hScreenDC,point.x,point.y,SRCCOPY);
			for(k=0;k<size.cy;k++)
			{
				for(j=0;j<size.cx;j++)
				{
					//UINT r=sqrt((k-64)*(k-64)+(j-64)*(j-64));
					//int x=cos(3.4
					*(pBits+(k*size.cx+j)*4)=*(pBits+(k*size.cx+(int)(sin(j/128.0*3.14/2)*127))*4);
					*(pBits+(k*size.cx+j)*4+1)=*(pBits+(k*size.cx+(int)(sin(j/128.0*3.14/2)*127))*4+1);
					*(pBits+(k*size.cx+j)*4+2)=*(pBits+(k*size.cx+(int)(sin(j/128.0*3.14/2)*127))*4+2);
					*(pBits+(k*size.cx+j)*4+3)=0x7f;
				}
			}
			//pTemp+=4;
			for(k=0;k<size.cy*size.cx;k++)
			{
				//hsv.hsv_to_rgb((sin(t/20.0)+1)/2.0,1.0f,1.0f,&r,&g,&b);
				//*(pTemp+3)=0x7f;
				//*(pTemp)=*(pTemp)*(*(pTemp+3))/0xff;
				//*(pTemp+1)=*(pTemp+1)*(*(pTemp+3))/0xff;
				//*(pTemp+2)=*(pTemp+2)*(*(pTemp+3))/0xff;
				//*(pTemp)=((*(pTemp-4)+*(pTemp+4))/2+*(pTemp))/2;
				//*(pTemp+1)=((*(pTemp+1-4)+*(pTemp+1+4))/2+*(pTemp+1))/2;
				//*(pTemp+2)=((*(pTemp+2-4)+*(pTemp+2+4))/2+*(pTemp+2))/2;
				*(pTemp+3)=0x7f;
				*(pTemp)=*(pTemp)*(*(pTemp+3))/0xff;
				*(pTemp+1)=*(pTemp+1)*(*(pTemp+3))/0xff;
				*(pTemp+2)=*(pTemp+2)*(*(pTemp+3))/0xff;
				pTemp+=4;
			}*/
			/*TRIVERTEX        vert [4] ;
			GRADIENT_TRIANGLE    gTri[2];
			vert [0] .x       =  0;
			vert [0] .y       =  0;
			vert [0] .Red     =  
			vert [0] .Green   =  
			vert [0] .Blue    =  0x7f00;
			vert [0] .Alpha   =  0x7f00;

			vert [1] .x       =  128;
			vert [1] .y       =  0;
			vert [1] .Red     =  0x0000;
			vert [1] .Green   =  0x0000;
			vert [1] .Blue    =  0x0000;
			vert [1] .Alpha   =  0xff00;

			vert [2] .x       =  0;
			vert [2] .y       =  128; 
			vert [2] .Red     =  0x0000;
			vert [2] .Green   =  0x0000;
			vert [2] .Blue    =  0x000;
			vert [2] .Alpha   =  0xff00;

			gTri[0].Vertex1   = 0;
			gTri[0].Vertex2   = 1;
			gTri[0].Vertex3   = 2;*/
			/*for(i=0;i<1;i+=step)
			{
				hsv.hsv_to_rgb((int)(i*360+t)%360/360.0,0.0f,0.0f,&r,&g,&b);
				//glColor4f(r,g,b,1.0F);
				//glVertex3f(0.0f,0.0f,0.0f);
				vert [0] .x       =  0+64;
				vert [0] .y       =  0+64;
				vert [0] .Red     =  r*0xff00;
				vert [0] .Green   =  g*0xff00;
				vert [0] .Blue    =  b*0xff00;
				vert [0] .Alpha   =  (sin(t/10.0)+1)/2.0*0xff00;

				hsv.hsv_to_rgb((int)(i*360+t)%360/360.0,1.0,1.0,&r,&g,&b);
				//glVertex3f(cos(i*2*3.14),sin(i*2*3.14),0.0f);
				vert [1] .x       =  cos((i)*2*3.14)*64+64;
				vert [1] .y       =  sin((i)*2*3.14)*64+64;
				vert [1] .Red     =  r*0xff00;
				vert [1] .Green   =  g*0xff00;
				vert [1] .Blue    =  b*0xff00;
				vert [1] .Alpha   =  (sin(t/10.0)+1)/2.0*0xff00;

				hsv.hsv_to_rgb((int)((i+step)*360+t)%360/360.0,1.0,1.0,&r,&g,&b);
				//glVertex3f(cos((i-0.01)*2*3.14),sin((i-0.01)*2*3.14),0.0f);
				vert [2] .x       =  cos((i+step)*2*3.14)*64+64;
				vert [2] .y       =  sin((i+step)*2*3.14)*64+64;
				vert [2] .Red     =  r*0xff00;
				vert [2] .Green   =  g*0xff00;
				vert [2] .Blue    =  b*0xff00;
				vert [2] .Alpha   =  (sin(t/10.0)+1)/2.0*0xff00;
				//GradientFill(hDC,vert,4,&gTri,1,GRADIENT_FILL_TRIANGLE);
			}*/
			
			SetTextColor(hDC,0xffffff);
			SetBkColor(hDC,0x000000);
			SetBkMode(hDC,TRANSPARENT);
			//MoveToEx(hDC,0,0,NULL);
			//LineTo(hDC,128,128);
			_strtime(ntime);
			TextOut(hDC,0,0,ntime,8);
			//GradientFill(hDC,vert,4,&gTri,1,GRADIENT_FILL_TRIANGLE);
			//BitBlt(GetDC(NULL),0,0,128,128,hDC,0,0,SRCCOPY);
			//BitBlt(hDC,0,0,128,128,GetDC(NULL),point.x,point.y,SRCCOPY);
			//GetCursorPos(&point);
			UpdateLayeredWindow(hWnd,hScreenDC,&point,&size,hDC, &ptSrc,0,&blend,ULW_ALPHA);
			t+=1;
			break;
		case WM_LBUTTONDOWN:
			fwKeys = wParam;        // key flags 
			Lastx = LOWORD(lParam);  // horizontal position of cursor 
			Lasty = HIWORD(lParam);  // vertical position of cursor
			SetCapture(hWnd);
			GetCursorPos(&ptLast);
			bDrag=TRUE;
			break;
		case WM_LBUTTONUP:
			bDrag=FALSE;
			ReleaseCapture();
		
			break;
		case WM_MOUSEMOVE:
			if(bDrag==TRUE)
			{
				fwKeys = wParam;        // key flags 
				xPos = LOWORD(lParam);  // horizontal position of cursor 
				yPos = HIWORD(lParam);  // vertical position of cursor 
				//MoveWindow(hWnd,100,100,nWidth,nHeight,FALSE);
				GetWindowRect(hWnd,&rect);
				GetCursorPos(&ptNow);
				OffsetRect(&rect,ptNow.x-ptLast.x,ptNow.y-ptLast.y);
				point.x=rect.left;
				point.y=rect.top;
				//point.x+=ptNow.x-ptLast.x;
				//point.y+=ptNow.y-ptLast.y;
				ptLast.x=ptNow.x;
				ptLast.y=ptNow.y;
				//MoveWindow(hWnd,point.x,point.y,size.cx,size.cy,FALSE);
				UpdateLayeredWindow(hWnd,hScreenDC,&point,&size,hDC, &ptSrc,0,&blend,ULW_ALPHA);
				//MessageBeep(MB_OK);
			}
			break;

		case WM_COMMAND:
			wmId    = LOWORD(wParam); 
			wmEvent = HIWORD(wParam); 
			// Parse the menu selections:
			switch (wmId)
			{
				case IDM_ABOUT:
				   DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
				   break;
				case IDM_EXIT:
				   DestroyWindow(hWnd);
				   break;
				default:
				   return DefWindowProc(hWnd, message, wParam, lParam);
			}
			break;
		/*case WM_PAINT:
			hdc = BeginPaint(hWnd, &ps);
			// TODO: Add any drawing code here...
			RECT rt;
			GetClientRect(hWnd, &rt);
			DrawText(hdc, szHello, strlen(szHello), &rt, DT_CENTER);
			EndPaint(hWnd, &ps);
			break;*/
		case WM_DESTROY:
			KillTimer(hWnd,IDT_TIMER0);
			ReleaseDC(hWnd,hScreenDC);
			//SelectObject(hDC,hOldBitmap);
			DeleteDC(hDC);
			DeleteObject(hBitmap);
			delete [] data;
			PostQuitMessage(0);
			break;
		default:
			return DefWindowProc(hWnd, message, wParam, lParam);
   }
   return 0;
}

// Mesage handler for about box.
LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch (message)
	{
		case WM_INITDIALOG:
				return TRUE;

		case WM_COMMAND:
			if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) 
			{
				EndDialog(hDlg, LOWORD(wParam));
				return TRUE;
			}
			break;
	}
    return FALSE;
}

DrawAlarmLight(HDC hDC,float angle,float halfwidth)
{
	TRIVERTEX        vert [3] ;
	GRADIENT_TRIANGLE    gTri[1];
	float step=2*halfwidth/10;
	float v;
	gTri[0].Vertex1   = 0;
	gTri[0].Vertex2   = 1;
	gTri[0].Vertex3   = 2;
	for(v=angle-halfwidth;v<=angle+halfwidth-step;v+=step)
	{
		vert [0] .x       =  0+64;
		vert [0] .y       =  0+64;
		vert [0] .Red     =  0xff00;
		vert [0] .Green   =  0x0000;
		vert [0] .Blue    =  0x0000;
		vert [0] .Alpha   =  0x4000;

		vert [1] .x       =  cos(v)*64+64;
		vert [1] .y       =  sin(v)*64+64;
		vert [1] .Red     =  0x00;
		vert [1] .Green   =  0x00;
		vert [1] .Blue    =  0x00;
		vert [1] .Alpha   =  0x00;

		vert [2] .x       =  cos(v+step)*64+64;
		vert [2] .y       =  sin(v+step)*64+64;
		vert [2] .Red     =  0x00;
		vert [2] .Green   =  0x00;
		vert [2] .Blue    =  0x00;
		vert [2] .Alpha   =  0x00;
		GradientFill(hDC,vert,3,&gTri,1,GRADIENT_FILL_TRIANGLE);
	}
	angle+=3.14159265358*2/3.0;
	//angle+=3.14159265358;
	for(v=angle-halfwidth;v<=angle+halfwidth-step;v+=step)
	{
		vert [0] .x       =  0+64;
		vert [0] .y       =  0+64;
		vert [0] .Red     =  0x000;
		vert [0] .Green   =  0x000;
		vert [0] .Blue    =  0xff00;
		vert [0] .Alpha   =  0x4000;

		vert [1] .x       =  cos(v)*64+64;
		vert [1] .y       =  sin(v)*64+64;
		vert [1] .Red     =  0x00;
		vert [1] .Green   =  0x00;
		vert [1] .Blue    =  0x00;
		vert [1] .Alpha   =  0x00;

		vert [2] .x       =  cos(v+step)*64+64;
		vert [2] .y       =  sin(v+step)*64+64;
		vert [2] .Red     =  0x00;
		vert [2] .Green   =  0x00;
		vert [2] .Blue    =  0x00;
		vert [2] .Alpha   =  0x00;
		GradientFill(hDC,vert,3,&gTri,1,GRADIENT_FILL_TRIANGLE);
	}
	angle+=3.14159265358*2/3.0;
	for(v=angle-halfwidth;v<=angle+halfwidth-step;v+=step)
	{
		vert [0] .x       =  0+64;
		vert [0] .y       =  0+64;
		vert [0] .Red     =  0x0000;
		vert [0] .Green   =  0xff00;
		vert [0] .Blue    =  0x00;
		vert [0] .Alpha   =  0x4000;

		vert [1] .x       =  cos(v)*64+64;
		vert [1] .y       =  sin(v)*64+64;
		vert [1] .Red     =  0x00;
		vert [1] .Green   =  0x00;
		vert [1] .Blue    =  0x00;
		vert [1] .Alpha   =  0x00;

		vert [2] .x       =  cos(v+step)*64+64;
		vert [2] .y       =  sin(v+step)*64+64;
		vert [2] .Red     =  0x00;
		vert [2] .Green   =  0x00;
		vert [2] .Blue    =  0x00;
		vert [2] .Alpha   =  0x00;
		GradientFill(hDC,vert,3,&gTri,1,GRADIENT_FILL_TRIANGLE);
	}
	
}
DrawRadiationAlarm(HDC hDC,float angle)
{

	TRIVERTEX        vert [3] ;
	GRADIENT_TRIANGLE    gTri[1];
	float step=3.1415926/18;
	float v;
	float halfwidth=0.4;
	float step2=2*halfwidth/10;
	float r=64,r0=12,r1=16,r2=50;
	gTri[0].Vertex1   = 0;
	gTri[0].Vertex2   = 1;
	gTri[0].Vertex3   = 2;
	for(v=0;v<=2*3.1415926-step;v+=step)
	{
		vert [0] .x       =  0+64;
		vert [0] .y       =  0+64;
		vert [0] .Red     =  0xff00;
		vert [0] .Green   =  0xff00;
		vert [0] .Blue    =  0x0000;
		vert [0] .Alpha   =  0x7f00;

		vert [1] .x       =  cos(v)*r+64;
		vert [1] .y       =  sin(v)*r+64;
		vert [1] .Red     =  0x00;
		vert [1] .Green   =  0x00;
		vert [1] .Blue    =  0x00;
		vert [1] .Alpha   =  0x00;

		vert [2] .x       =  cos(v+step)*r+64;
		vert [2] .y       =  sin(v+step)*r+64;
		vert [2] .Red     =  0x00;
		vert [2] .Green   =  0x00;
		vert [2] .Blue    =  0x00;
		vert [2] .Alpha   =  0x00;
		GradientFill(hDC,vert,3,&gTri,1,GRADIENT_FILL_TRIANGLE);
	}
	for(int i=0;i<3;i++)
	{
		for(v=angle-halfwidth;v<=angle+halfwidth-step2;v+=step2)
		{
			vert [0] .x       =  cos(v)*r1+64;
			vert [0] .y       =  sin(v)*r1+64;
			vert [0] .Red     =  0x000;
			vert [0] .Green   =  0x000;
			vert [0] .Blue    =  0x000;
			vert [0] .Alpha   =  0xff00;

			vert [1] .x       =  cos(v)*r2+64;
			vert [1] .y       =  sin(v)*r2+64;
			vert [1] .Red     =  0x00;
			vert [1] .Green   =  0x00;
			vert [1] .Blue    =  0x00;
			vert [1] .Alpha   =  0xff00;

			vert [2] .x       =  cos(v+step2)*r2+64;
			vert [2] .y       =  sin(v+step2)*r2+64;
			vert [2] .Red     =  0x00;
			vert [2] .Green   =  0x00;
			vert [2] .Blue    =  0x00;
			vert [2] .Alpha   =  0xff00;
			GradientFill(hDC,vert,3,&gTri,1,GRADIENT_FILL_TRIANGLE);
			vert [0] .x       =  cos(v+step2)*r1+64;
			vert [0] .y       =  sin(v+step2)*r1+64;
			vert [0] .Red     =  0x000;
			vert [0] .Green   =  0x000;
			vert [0] .Blue    =  0x000;
			vert [0] .Alpha   =  0xff00;

			vert [1] .x       =  cos(v)*r1+64;
			vert [1] .y       =  sin(v)*r1+64;
			vert [1] .Red     =  0x00;
			vert [1] .Green   =  0x00;
			vert [1] .Blue    =  0x00;
			vert [1] .Alpha   =  0xff00;

			vert [2] .x       =  cos(v+step2)*r2+64;
			vert [2] .y       =  sin(v+step2)*r2+64;
			vert [2] .Red     =  0x00;
			vert [2] .Green   =  0x00;
			vert [2] .Blue    =  0x00;
			vert [2] .Alpha   =  0xff00;
			GradientFill(hDC,vert,3,&gTri,1,GRADIENT_FILL_TRIANGLE);
		}
		angle+=3.14159265358*2/3.0;
	}
	for(v=0;v<=2*3.1415926-step;v+=step)
	{
		vert [0] .x       =  0+64;
		vert [0] .y       =  0+64;
		vert [0] .Red     =  0x00;
		vert [0] .Green   =  0x00;
		vert [0] .Blue    =  0x00;
		vert [0] .Alpha   =  0xff00;

		vert [1] .x       =  cos(v)*r0+64;
		vert [1] .y       =  sin(v)*r0+64;
		vert [1] .Red     =  0x00;
		vert [1] .Green   =  0x00;
		vert [1] .Blue    =  0x00;
		vert [1] .Alpha   =  0xff00;

		vert [2] .x       =  cos(v+step)*r0+64;
		vert [2] .y       =  sin(v+step)*r0+64;
		vert [2] .Red     =  0x00;
		vert [2] .Green   =  0x00;
		vert [2] .Blue    =  0x00;
		vert [2] .Alpha   =  0xff00;
		GradientFill(hDC,vert,3,&gTri,1,GRADIENT_FILL_TRIANGLE);
	}
}